<%
Function del()
	tmp_time = Request.QueryString("tmp_time")
	tmp_file = Request.QueryString("tmp_file")
	strSourceFile = Server.MapPath("database.xml")
	Set objXML = Server.CreateObject("Microsoft.XMLDOM")
	objXML.load(strSourceFile)
	Set objRootList = objXML.documentElement.selectSingleNode("DataList")
	For iii = 0 To objRootList.childNodes.Length -1
			If tmp_time = Trim(objRootList.childNodes.Item(iii).childNodes.Item(2).text) Then
					tmp_file = objRootList.childNodes.Item(iii).childNodes.Item(1).text
					thisid = iii
					Exit For
			End If
	Next

	objRootList.removeChild(objRootList.childNodes(thisid))
	objXML.save(strSourceFile)
	Set objXML = Nothing

	DelFunctions("tc_"&tmp_file)
	Call SetBlogHint_Custom("√ 删除成功.")
	Response.Redirect "main.asp"
End Function

Function Save()
	tmp_name = Request.Form("tmp_name")
	tmp_file = Request.Form("tmp_file")
	tmp_time = Request.Form("tmp_time")
	tmp_info = Request.Form("tmp_info")
	tmp_date = Request.Form("tmp_date")
	tmp_link = Request.Form("tmp_link")
	operateact = Request.QueryString("operateact")

	Dim rootOldNode, rootNewNode, brstr, XMLnode, objXML2, tmp_id
	brstr = Chr(13)&Chr(10)&Chr(9)
	strSourceFile = Server.MapPath("database.xml")
	Set objXML = Server.CreateObject("Microsoft.XMLDOM")
	objXML.load(strSourceFile)
	Set objRootList = objXML.documentElement.selectSingleNode("DataList")

	If operateact <> "update" Then ''INSERT
		XMLnode = brstr&"<data>"&brstr & _
				  "<name>"&tmp_name&"</name>"&brstr & _
				  "<file>"&tmp_file&"</file>"&brstr & _
				  "<time>"&tmp_time&"</time>"&brstr & _
				  "<date>"&tmp_date&"</date>"&brstr & _
				  "<link>"&tmp_link&"</link>"&brstr & _
				  "<info>"&tmp_info&"</info>"&brstr & _
				  "</data>"&Chr(13)
		'Response.Write(XMLnode)
		Set objXML2 = Server.CreateObject("Microsoft.XMLDOM")
		objXML2.loadXML(XMLnode)
		Set rootNewNode = objXML2.documentElement
		objRootList.appEndChild(rootNewNode)
	Else
		For iii = 0 To objRootList.childNodes.Length -1
				If tmp_time = Trim(objRootList.childNodes.Item(iii).childNodes.Item(2).text) Then
						thisid = iii
						Exit For
				End If
		Next
		Set rootOldNode = objRootList.childNodes.Item(thisid)
		XMLnode = brstr&"<data>"&brstr & _
				  "<name>"&tmp_name&"</name>"&brstr & _
				  "<file>"&tmp_file&"</file>"&brstr & _
				  "<time>"&tmp_time&"</time>"&brstr & _
				  "<date>"&tmp_date&"</date>"&brstr & _
				  "<link>"&tmp_link&"</link>"&brstr & _
				  "<info>"&tmp_info&"</info>"&brstr & _
				  "</data>"&Chr(13)
		'Response.Write(XMLnode)
		Set objXML2 = Server.CreateObject("Microsoft.XMLDOM")
		objXML2.loadXML(XMLnode)
		Set rootNewNode = objXML2.documentElement
		objRootList.ReplaceChild rootNewNode, rootOldNode
	End If
	objXML.save(strSourceFile)
	Set objXML = Nothing
	Set objXML2 = Nothing

	Call SaveFunctions("tc_"&tmp_file,tmp_name&"倒计时","div_tc_"&tmp_file,"div",innerHtml)
	Call SetBlogHint_Custom("√ 操作成功,已添加/更新侧栏模块,请到侧栏管理中查找使用.")
	Response.Redirect "main.asp"
End Function


Function Edit()
	tmp_time = Request.QueryString("tmp_time")
	If Len(tmp_time) = 0 Then 'NEW
		operateact = "addnew"
		tmp_name = ""
		tmp_file = ""
		tmp_time = now()
		tmp_date = ""
		tmp_link = ""
		tmp_info= ""
	Else
		operateact = "update"
		strSourceFile = Server.MapPath("database.xml")
		Set objXML = Server.CreateObject("Microsoft.XMLDOM")
		objXML.load(strSourceFile)
		Set objRootList = objXML.documentElement.selectSingleNode("DataList")
		For iii = 0 To objRootList.childNodes.Length -1
			If tmp_time= Trim(objRootList.childNodes.Item(iii).childNodes.Item(2).text) Then
				tmp_name = objRootList.childNodes.Item(iii).childNodes.Item(0).text
				tmp_file = objRootList.childNodes.Item(iii).childNodes.Item(1).text
				tmp_date = objRootList.childNodes.Item(iii).childNodes.Item(3).text
				tmp_link = objRootList.childNodes.Item(iii).childNodes.Item(4).text
				tmp_info = objRootList.childNodes.Item(iii).childNodes.Item(5).text
				Exit For
			End If
		Next
		Set objXML = Nothing
	End If
	If operateact = "update" then
	Response.Write "<div class=""divHeader"">编辑倒计时</div>"
	Response.Write "<div class=""SubMenu""><a href=""?act=list""><span class=""m-left"">列表</span></a><a href=""?act=Edit""><span class=""m-left m-now"">添加</span></a></div>"
	Else
	Response.Write "<div class=""divHeader"">添加倒计时</div>"
	Response.Write "<div class=""SubMenu""><a href=""?act=list""><span class=""m-left"">列表</span></a><a href=""?act=Edit""><span class=""m-left  m-now"">添加</span></a></div>"
	End If
	Response.Write "<div id=""divMain2"">"
	Response.Write "<form id=""edit"" name=""edit"" method=""post"">"
	Response.Write "<p>标题: <input id=""tmp_name"" name=""tmp_name"" style=""width:50%"" type=""text"" value="""& tmp_name &""" />(*)</p>"
	If operateact = "update" then
	Response.Write "<p>文件: <input id=""tmp_file"" name=""tmp_file"" style=""color:#666666;width:50%"" type=""text"" value="""& tmp_file &""" / readonly>(*) 编辑状态下不可修改</p>"
	Else
	Response.Write "<p>文件: <input id=""tmp_file"" name=""tmp_file"" style=""width:50%"" type=""text"" value="""& tmp_file &""" />(*) 必须为英文</p>"
	End If
	Response.Write "<p>日期: <input id=""tmp_date"" name=""tmp_date"" style=""width:50%"" type=""text"" value="""& tmp_date &""" />(*)</p>"
	Response.Write "<p>链接: <input id=""tmp_link"" name=""tmp_link"" style=""width:50%"" type=""text"" value="""& tmp_link &""" /></p>"
	Response.Write "<input id=""tmp_time"" name=""tmp_time""  type=""hidden"" value="""& tmp_time &""" />"

	Response.Write "<p>其他: <input id=""tmp_info"" name=""tmp_info"" style=""width:50%"" type=""text"" value="""& tmp_info &""" /></p>"
	Response.Write "<p><input type=""submit"" class=""button"" value="""& ZC_MSG087 &""" id=""btnPost"" onclick='return checkCatetime();' /></p>"

	Response.Write "</form>"
	Response.Write "</div>"
%>
<script>
function checkCatetime(){
	document.getElementById("edit").action="main.asp?act=Save&operateact=<%=operateact%>";
	if(!document.getElementById("tmp_name").value){
		alert('请填写名称!');
		return false
	}
	if(!document.getElementById("tmp_file").value){
		alert('请填写文件名!');
		return false
	}
	if(!document.getElementById("tmp_date").value){
		alert('请填写日期!');
		return false
	}
}
</script>
<%
End Function
Function List()
	Response.Write "<div class=""divHeader"">倒计时列表</div>"
	Response.Write "<div class=""SubMenu""><a href=""?act=list""><span class=""m-left m-now"">列表</span></a><a href=""?act=Edit""><span class=""m-left"">添加</span></a></div>"
	Response.Write "<div id=""divMain2"">"
	Response.Write "<table border=""1"" width=""100%"" cellspacing=""1"" cellpadding=""1"">"
	Response.Write "<tr bgcolor=""#DAE2E8"">"
	Response.Write "<td width=""30%"">名称</td>"
	Response.Write "<td width=""15%"">日期</td>"
	Response.Write "<td width=""40%"">预览</td>"
	Response.Write "<td width=""15%"" align=""center"">操作</td>"
	Response.Write "</tr>"

	strSourceFile = Server.MapPath("database.xml")
	Set objXML = Server.CreateObject("Microsoft.XMLDOM")
	objXML.load(strSourceFile)
	Set objRootList = objXML.documentElement.selectSingleNode("DataList")
	For iii = 0 To objRootList.childNodes.Length -1
		tmp_name = objRootList.childNodes.Item(iii).childNodes.Item(0).text
		tmp_file = objRootList.childNodes.Item(iii).childNodes.Item(1).text
		tmp_time = objRootList.childNodes.Item(iii).childNodes.Item(2).text
		tmp_date = objRootList.childNodes.Item(iii).childNodes.Item(3).text
		tmp_link = objRootList.childNodes.Item(iii).childNodes.Item(4).text
		Response.Write "<tr>"
		Response.Write "<td>"&tmp_name&"</td>"
		Response.Write "<td>"&tmp_date&"</td>"
		Response.Write "<td>"&innerHtml&"</td>"
		Response.Write "<td align=center><a href=""?act=Edit&tmp_file=" & tmp_file & "&tmp_time=" & tmp_time & """>[编辑]</a> <a href=""?act=del&tmp_file=" & tmp_file & "&tmp_time=" & tmp_time & """ onclick=""return window.confirm('你将删除此项,并删除对应的侧栏模块,确定吗?');"">[删除]</a></td>"
		Response.Write "</tr>"
	Next
	Set objXML = Nothing
	Response.Write "</table>"
	Response.Write "</div>"
End Function

Function innerHtml
	innerHtml = "<div style="""">" & vbCrLf
	innerHtml = innerHtml & "<a href=""" & tmp_link & """ target=""_blank"">" & vbCrLf
	innerHtml = innerHtml & "<script language=""JavaScript"">" & vbCrLf
	innerHtml = innerHtml & "var urodz= new Date(""" & tmp_date & """);" & vbCrLf
	innerHtml = innerHtml & "var s=""" & tmp_name & """;" & vbCrLf
	innerHtml = innerHtml & "var now = new Date();" & vbCrLf
	innerHtml = innerHtml & "var ile = urodz.getTime() - now.getTime();" & vbCrLf
	innerHtml = innerHtml & "var dni = Math.floor(ile / (1000 * 60 * 60 * 24))+1;" & vbCrLf
	innerHtml = innerHtml & "if (dni > 3)" & vbCrLf
	innerHtml = innerHtml & "document.write(""距离""+s+""还有""+dni +""天"");" & vbCrLf
	innerHtml = innerHtml & "else if (dni <= 3)" & vbCrLf
	innerHtml = innerHtml & "document.write(""<span style=color:red>距离""+s+""只有""+dni +""天</span>"");" & vbCrLf
	innerHtml = innerHtml & "else" & vbCrLf
	innerHtml = innerHtml & "document.write(""""+s+""已经过了哦！"");" & vbCrLf
	innerHtml = innerHtml & "</script>" & vbCrLf
	innerHtml = innerHtml & "</a></div>"
End Function

Function SaveFunctions(id,name,htmlid,ftype,content)
	GetFunction()
	Dim objfunction
	Set objfunction=New TFunction
	If FunctionMetas.GetValue(id)=TimeCounter_Empty Then
		objfunction.ID=0
		objfunction.Name=name
		objfunction.FileName=id
		objfunction.HtmlID=htmlid
		objfunction.Ftype=ftype
		objfunction.Order=0
		objfunction.SidebarID=0
		If Right(ZC_BLOG_VERSION,6)>121221 Then
			objfunction.ViewType="html"
			objFunction.Source="plugin_TimeCounter"
		End If
		objfunction.isSystem=False
		objfunction.Content=content
		objfunction.Save
	Else
		Functions(FunctionMetas.GetValue(id)).Content=content
		Functions(FunctionMetas.GetValue(id)).Post()
		Functions(FunctionMetas.GetValue(id)).SaveFile
	End If
End Function

Function DelFunctions(id)
	GetFunction()
	Dim objfunction
	Set objfunction=New TFunction
	objfunction.ID=FunctionMetas.GetValue(id)
	objfunction.FileName=id
	objfunction.Del
End Function
%>